package com.spt.springbootzhsx.controller;

import com.spt.springbootzhsx.entity.Order;
import com.spt.springbootzhsx.entity.back.OrderBack;
import com.spt.springbootzhsx.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RestController
@RequestMapping(value="/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @GetMapping(value="/getAllOrder")
    public ArrayList<OrderBack> getAllOrder(){
        return orderService.getAllOrder();
    }

    @GetMapping(value = "/getOrderByUnameOrMname/{key}")
    public ArrayList<OrderBack> getOrderByUnameOrMname(@PathVariable("key") String key){
        return orderService.getOrderByUnameOrMname(key);
    }

    @PostMapping(value="/addOrder")
    public String addOrder(@RequestBody Order order){
        return orderService.addOrder(order);
    }

    @GetMapping(value="/getOrderByPid/{pid}")
    public ArrayList<Order> getOrderByPid(@PathVariable("pid") Integer pid){
        return orderService.getOrderByPid(pid);
    }

    @GetMapping(value="/getOrderHistory/{uid}")
    public ArrayList<OrderBack> getOrderHistory(@PathVariable("uid") Integer uid){
        return orderService.getOrderHistory(uid);
    }

    @GetMapping(value="/deleteOrder/{oid}")
    public String deleteOrder(@PathVariable("oid") Integer oid){
        return orderService.deleteOrder(oid);
    }
}
